{extend name='public/base' /}

{block name="css"}

<!-- Data Tables -->
<link href="__BCSS__/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">

{/block}

{block name="content"}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-title">
                <h5>表备份卷</h5>
                <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                </div>
            </div>
            <div class="ibox-content">

                    <table class="table table-striped table-bordered table-hover dataTables-example">
                        <thead>
                        <tr>
                            <th>数据库名称</th>
                            <th>卷数</th>
                            <th>压缩</th>
                            <th>数据大小</th>
                            <th>备份时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name='list' item='data'}
                        <tr>
                            <td>{$data.time|ftime}</td>
                            <td>{$data.part}</td>
                            <td>{$data.compress}</td>
                            <td>{$data.size|format_bytes}</td>
                            <td>{$key}</td>
                            <td class="status">-</td>
                            <td class="action">
                                <a class="db-down btn btn-primary btn-xs" href="{:url('DataBackup/down',['time'=>$data['time']])}">下载</a>&nbsp;
                                <!--   <a class="db-import" href="{:url('DataBackup/import',['time'=>$data['time']])}">还原</a>&nbsp;-->
                                <a class="ajax-get confirm  btn btn-danger btn-xs" href="{:url('DataBackup/del',['time'=>$data['time']])}">删除</a>
                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>

            </div>
        </div>

    </div>
</div>

{/block}


{block name="js"}

<!-- Data Tables -->
<script src="__BJS__/plugins/dataTables/jquery.dataTables.js"></script>
<script src="__BJS__/plugins/dataTables/dataTables.bootstrap.js"></script>

<script>

    $(document).ready(function () {
        $('.dataTables-example').dataTable();

    });

    layui.use(['jquery','layer'],function(){
        window.$ = layui.$;
        var layer = layui.layer;

        $(".db-import").click(function(){
            var self = this, status = ".";
            $(this).parent().prevAll('.status').html("").html('等待还原');

            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;

            function success(data){
                if(data.code==1){
                    $(self).parent().prev().text(data.msg);
                    if(data.data.part){
                        $.get(self.href,
                            {"part" : data.data.part, "start" : data.data.start},
                            success,
                            "json"
                        );
                    }  else {
                        layer.alert(data.msg);
                        //window.onbeforeunload = function(){ return null; }
                    }
                } else {
                    layer.alert(data.msg);
                }
            }
        });
    });
</script>

{/block}